package com.shanghaiyimu.yimiyangche.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.entity.CheXingEntity;

import java.util.List;

/**
 * Author:ShangHaiYiMu
 * Time:2017/8/1   9:29
 * Description:CheXingAdapter
 */

public class CheXingAdapter extends BaseAdapter {
    private Context context;
    private List<CheXingEntity.ResultBean.DataBean> datas;

    public CheXingAdapter(Context context, List<CheXingEntity.ResultBean.DataBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas!=null?datas.size():0;
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.chexi_listview_item,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.textView.setText(datas.get(position).getPyear()+"");
        CheXingAdapteradapter adapteradapter = new CheXingAdapteradapter(context,datas.get(position).getChexing_list());
        holder.listView.setAdapter(adapteradapter);
        holder.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
               TextView content = (TextView) view.findViewById(R.id.list_lv_item_pinpia);
                contents = content.getText().toString();
                chexingid = content.getTag().toString();
                setCheXing.onChngeCheXing(content.getText().toString(),content.getTag().toString());


            }
        });
        return convertView;
    }
    private String contents,chexingid;
    public interface SetCheXing{
        void onChngeCheXing(String cheing,String cheingId);
    }

    private SetCheXing setCheXing ;
    public void set(SetCheXing s) {
        setCheXing = s;
    }


    static class ViewHolder{
        TextView textView;
        ListView listView;

        public ViewHolder(View view) {
            textView = (TextView) view.findViewById(R.id.item_item_title);
            listView = (ListView) view.findViewById(R.id.item_item_item_listview);
        }
    }
}
